#include "cameracontrol.h"
#include <QDebug>

static char values[14]={"udlr1234nfios"};

CameraControl::CameraControl(const QString &url):
    _url(url)
{

}

void CameraControl::setUrl(const QString &url)
{
    _url = url;
}

void CameraControl::setStep(int step)
{
    _step = step;
}

void CameraControl::setSpeed(int speed)
{
    _speed = speed;
}

void CameraControl::setChannelId(const uint32_t channelId)
{
    _channelId = channelId;
}

QString CameraControl::getMoveUrl(enum MoveCommand command)
{
    QString temp(_url);
    _url.append("/api/ptz/control");
    KVQuery kvs;
    kvs.add("channeId",QString::number(_channelId));
    kvs.add("speed",QString::number(_speed));
    kvs.add("value",QString(values[command]));
    QUrl res(_url);
    res.setQuery(kvs.getQueryParameter());
    return res.toString();
}

QString CameraControl::getHistoryVideo(const QDateTime& start_time, const QDateTime& end_time)
{
    QString temp(_url);
    temp.append("/api/record/hls/ts/record.ts");
    KVQuery kvs;
    kvs.add("start_time",QString::number(start_time.toMSecsSinceEpoch()));//转化为时间戳，ms级别
    kvs.add("end_time",QString::number(end_time.toMSecsSinceEpoch()));
    kvs.add("channel",QString::number(_channelId));

    QUrl res(_url);
    res.setQuery(kvs.getQueryParameter());
    return res.toString();

}

